<div class="app-post-form">
  <%= form_for [:admin, @post], html: {class: 'uk-form uk-form-stacked'} do |f| %>
      <div class="uk-form-row uk-grid">
        <div class="uk-text-right uk-width-1-10">
          <%= f.label :title, nil, class: 'uk-form-label' %>
        </div>
        <div class="uk-form-controls uk-width-9-10">
          <%= f.text_field :title, class: 'uk-width-1-1' %>
        </div>
      </div>

      <div class="uk-form-row uk-grid">
        <%= f.fields_for :post_category do |p_c_f|%>
            <div class="uk-text-right uk-width-1-10">
              <%= p_c_f.label :category_id, nil, class: 'uk-form-label' %>
            </div>
            <div class="uk-form-controls uk-width-9-10">
              <%= p_c_f.select :category_id, options_from_collection_for_select(Category.all, :id, :name, p_c_f.object.category_id),
                               {prompt: '选择分类'}, class: 'uk-width-1-1'%>
            </div>
        <% end %>
      </div>

      <div class="uk-form-row uk-grid">
        <div class="uk-text-right uk-width-1-10">
          <%= f.label :slug, nil, class: 'uk-form-label' %>
        </div>
        <div class="uk-form-controls uk-width-9-10">
          <%= f.text_field :slug, class: 'uk-width-1-1' %>
        </div>
      </div>

      <div class="uk-form-row uk-grid">
        <div class="uk-text-right uk-width-1-10">
          <%= f.label :published_at, nil, class: 'uk-form-label' %>
        </div>
        <div class="uk-form-controls uk-width-9-10">
          <%= f.text_field :published_at, value: f.object.published_time, class: 'uk-width-1-1', 'data-uk-datepicker' => %w{{format:'YYYY-MM-DD'}} %>
        </div>
      </div>

      <div class="uk-form-row">
        <a href="#image-panel" data-uk-offcanvas class="uk-button">打开图片侧栏</a>
      </div>

      <div class="uk-form-row uk-grid">
        <div class="uk-form-controls uk-width-9-10 uk-push-1-10">
          <%= f.text_area :body, class: 'uk-width-1-1', 'data-uk-htmleditor' => '{markdown:true}' %>
        </div>
      </div>

      <div class="uk-form-row uk-clearfix">
        <%= f.submit nil, class: 'uk-button uk-button-primary uk-button-large uk-float-right' %>
      </div>
  <% end %>
</div>

<div id="image-panel" class="uk-offcanvas">
  <div class="uk-offcanvas-bar">
    <div class="uk-panel">
        <div class="uk-grid">
          <%= form_tag admin_attachments_path, id: 'upload-image-form' do %>
            <%= file_field_tag :file, id: 'upload-image' %>
          <% end %>
        </div>
    </div>
    <ul class="uk-panel" id="uploaded-image-list">
        <%= render partial: 'admin/attachments/attachment', collection: Attachment.order(id: :desc), as: :attachment %>
    </ul>
  </div>
</div>